package org.fast.develop.logicflow.runtime.node;

import cn.hutool.core.bean.BeanUtil;
import org.fast.develop.logicflow.core.meta.base.properties.Properties;
import org.fast.develop.logicflow.core.meta.base.Resource;
import org.fast.develop.logicflow.runtime.instance.LogicFlowInstance;
import org.fast.develop.logicflow.runtime.task.delegate.DelegateTask;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 莫寅
 * @createTime 2022-11-24 11:30
 * @desc：
 */
public class LogicFlowNode implements DelegateTask {


    private Map<String, Object> variables;

    /**
     * 节点的Json属性
     */
    private Resource element;

    /**
     * 节点列表中的下一个节点
     */
    private List<LogicFlowNode> nextNodes = new ArrayList<>();

    /**
     * 节点列表中的上一个节点
     */
    private List<LogicFlowNode> prevNodes = new ArrayList<>();

    private LogicFlowInstance logicFlowInstance;

    public Resource getElement() {
        return element;
    }

    public void setElement(Resource element) {
        this.element = element;
    }

    public List<LogicFlowNode> getNextNodes() {
        return nextNodes;
    }

    public void setNextNodes(List<LogicFlowNode> nextNodes) {
        this.nextNodes = nextNodes;
    }

    public List<LogicFlowNode> getPrevNodes() {
        return prevNodes;
    }

    public void setPrevNodes(List<LogicFlowNode> prevNodes) {
        this.prevNodes = prevNodes;
    }

    @Override
    public Map<String, Object> getVariables() {
        return variables;
    }

    @Override
    public Map<String, Object> getVariableInstances() {
        return logicFlowInstance.getVariables();
    }

    public void setVariables(Map<String, Object> variables) {
        this.variables = variables;
    }

    public LogicFlowInstance getLogicFlowInstance() {
        return logicFlowInstance;
    }

    public void setLogicFlowInstance(LogicFlowInstance logicFlowInstance) {
        this.logicFlowInstance = logicFlowInstance;
    }

    @Override
    public Properties getResourceProperties(){
        Class<Properties> propertiesClass = (Class<Properties>) element.getProperties().getClass();
        return BeanUtil.copyProperties(this.element.getProperties(), propertiesClass);
    }
}
